package com.iamteer.day23;

import java.io.IOException;
import java.net.DatagramPacket;
import java.net.DatagramSocket;
import java.net.InetAddress;

/**
飞Q数据格式：
	version:time:sender:ip:flag:content;
	
 */
public class FeiQ {

	public static void main(String[] args) throws IOException {
		//1. 建立 UDP 服务
		DatagramSocket socket = new DatagramSocket();
		//2. 准备数据
		String content = "Hi FeiQ";
		byte[] buf = makeFrame(content);
		//3. 封装数据
		DatagramPacket packet = new DatagramPacket(buf, buf.length, InetAddress.getByName("192.168.1.255"),9090);
		//4. 发送数据
		socket.send(packet);
		//5. 关闭资源
		socket.close();
	}
	
	public static byte[] makeFrame(String content) {
		StringBuilder ret = new StringBuilder();
		ret.append("1.0:");
		ret.append(System.currentTimeMillis() + ":");
		ret.append("Chuck:");
		ret.append("192.168.1.110:");
		ret.append("32:");
		ret.append(content);
		
		return ret.toString().getBytes();
	}
}
